{% extends 'inventory/base.html' %}

{% block title %}{% if category %}编辑分类{% else %}添加分类{% endif %} - {{ block.super }}{% endblock %}

{% block content %}
<div class="row mb-4">
    <div class="col-12">
        <div class="card">
            <div class="card-body">
                <div class="d-flex justify-content-between align-items-center mb-4">
                    <h2 class="card-title mb-0">{% if category %}编辑分类{% else %}添加分类{% endif %}</h2>
                    <a href="{% url 'category_list' %}" class="btn btn-outline-secondary">
                        <i class="bi bi-arrow-left me-1"></i> 返回列表
                    </a>
                </div>
                
                <form method="post" novalidate>
                    {% csrf_token %}
                    
                    <div class="mb-3">
                        <label for="id_name" class="form-label">分类名称</label>
                        {{ form.name.errors }}
                        <input type="text" name="name" id="id_name" class="form-control {% if form.name.errors %}is-invalid{% endif %}" value="{{ form.name.value|default:'' }}" required>
                        {% if form.name.errors %}
                            <div class="invalid-feedback">{{ form.name.errors.0 }}</div>
                        {% endif %}
                    </div>
                    
                    <div class="mb-3">
                        <label for="id_description" class="form-label">分类描述</label>
                        {{ form.description.errors }}
                        <textarea name="description" id="id_description" class="form-control {% if form.description.errors %}is-invalid{% endif %}" rows="4">{{ form.description.value|default:'' }}</textarea>
                        {% if form.description.errors %}
                            <div class="invalid-feedback">{{ form.description.errors.0 }}</div>
                        {% endif %}
                    </div>
                    
                    <div class="d-flex justify-content-end gap-2">
                        <a href="{% url 'category_list' %}" class="btn btn-outline-secondary">取消</a>
                        <button type="submit" class="btn btn-primary">保存</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}